/**
 * 
 */
package com.nari.interfaces.decipher.common;

import java.math.BigDecimal;

import com.nari.heatshare.model.IHeatMeterTypeParamDict;
import com.nari.interfaces.model.IHeatMeterData24Gather;

/**
 * 热量表数据精度修正工具类
 * @author Xiaopeng
 * @date 2014-6-24
 */
public class HeatMeterDataPrecisionReviser {

	/**
	 * 修正热量表数据精度等信息
	 * 说明：热量表数据原始解析信息中状态字是四个字符的的BCD码[S3S2 S1S0]
	 * 其中S3S2表示热量表抄收数据的精度类型，S0表示报错信息
	 * @param meterData
	 * @param typeParam
	 * @return
	 * @author Xiaopeng
	 * @date 2014-6-24
	 */
	public static IHeatMeterData24Gather reviseMeterDataPrecision(IHeatMeterData24Gather meterData, 
			IHeatMeterTypeParamDict typeParam) {
		//结算日热量修正
		double settleAccountHeatPrecision = Math.pow(10, -typeParam.getSettleAccountHeatPrecision());
		double settleAccountHeat = new BigDecimal(String.valueOf(meterData.getSettleAccountHeat()))
				.multiply(new BigDecimal(String.valueOf(settleAccountHeatPrecision)))
				.doubleValue();
		meterData.setSettleAccountHeat(settleAccountHeat);
		//累计热量修正
		double sumHeatPrecision = Math.pow(10, -typeParam.getSumHeatPrecision());
		double sumHeat = new BigDecimal(String.valueOf(meterData.getSumHeat()))
				.multiply(new BigDecimal(String.valueOf(sumHeatPrecision)))
				.doubleValue();
		meterData.setSumHeat(sumHeat);
		//热功率修正
		double heatPowerPrecision = Math.pow(10, -typeParam.getHeatPowerPrecision());
		double heatPower = new BigDecimal(String.valueOf(meterData.getHeatPower()))
				.multiply(new BigDecimal(String.valueOf(heatPowerPrecision)))
				.doubleValue();
		meterData.setHeatPower(heatPower);
		//瞬时流量修正
		double instantFlowPrecision = Math.pow(10, -typeParam.getInstantFlowPrecision());
		double instantFlow = new BigDecimal(String.valueOf(meterData.getInstantFlow()))
				.multiply(new BigDecimal(String.valueOf(instantFlowPrecision)))
				.doubleValue();
		meterData.setInstantFlow(instantFlow);
		//累计流量修正
		double sumFlowPrecision = Math.pow(10, -typeParam.getSumFlowPrecision());
		double sumFlow = new BigDecimal(String.valueOf(meterData.getSumFlow()))
				.multiply(new BigDecimal(String.valueOf(sumFlowPrecision)))
				.doubleValue();
		meterData.setSumFlow(sumFlow);
		//供水温度修正
		double supplyTemperaturePrecision = Math.pow(10, -typeParam.getSupplyTemperaturePrecision());
		double supplyTemperature = new BigDecimal(String.valueOf(meterData.getSupplyTemperature()))
				.multiply(new BigDecimal(String.valueOf(supplyTemperaturePrecision)))
				.doubleValue();
		meterData.setSupplyTemperature(supplyTemperature);
		//回水温度修正
		double backTemperaturePrecision = Math.pow(10, -typeParam.getBackTemperaturePrecision());
		double backTemperature = new BigDecimal(String.valueOf(meterData.getBackTemperature()))
				.multiply(new BigDecimal(String.valueOf(backTemperaturePrecision)))
				.doubleValue();
		meterData.setBackTemperature(backTemperature);
		//累计运行时间
		double runHoursPrecision = Math.pow(10, -typeParam.getRunHoursPrecision());
		double runHours = new BigDecimal(String.valueOf(meterData.getRunHours()))
				.multiply(new BigDecimal(String.valueOf(runHoursPrecision)))
				.doubleValue();
		meterData.setRunHours(runHours);
		//异常信息
		String wrongInfo = HeatMeterDataProtocolDecipher.decipherWrongCode(meterData.getWrongInfo());
		meterData.setWrongInfo(wrongInfo);
		return meterData;
	}
}
